#pragma once
#include <bondlib/RealTimeDeal/IRealTimeDealModel.h>
#include <qbprotocol/include/SSQBModel.h>

#include <QWidget>
#include <vector>

#include "../Filter/FilterInterface.h"
#include "../RealTimeDeal/RealTimeDealModel.h"
#include "RealdealDefines.h"

enum tipsMenu {
  BondDetial,
  QuotationWindow,
  MarginWindow,
  BondSimilar,
  TrialCalculatin,
  HoldCalculatin,
  CopyBondShortName,
  CopyPrice,
  AddDefaultFollow,
  AddFollow,
  SetBondReminder
};

class SVirtualTable;
class DefaultTableModel;
class STableColumnSet;
class CEnviFilter;
class QMenu;
class RealDealTable : public QWidget, public IFlasher {
 public:
  RealDealTable(QWidget* parent);

  virtual void setEnviFilterPtr(CEnviFilter* pEnvi, BLHCONDITION* pBlh) {
    m_pEnviFilter = pEnvi;
    m_pBlh = pBlh;
  }
  virtual void setFilterCondition(FilterCondition* pFilterCond);
  void changeParam(bool showAll, int nCorpID = -999);
  void onFilterChange(bool v);

 protected:
  void initTable();
  void updateTable(bool resetScroll = false, int selRow = -1);
  void updateSpecialListWidth();
  void sortHeader(int col, bool desc, bool reset = false);
  void onBrokerSelChanged();

  void resizeEvent(QResizeEvent* event) override;
  void addFlash(std::string id) override;
  void removeFlash(std::string id) override;

 protected slots:
  void onDealMarketPushAll(int funcId, QList<xQBMarketStreamUnit_c>);
  void onHeaderSort(int col);
  void onContextMenu(QPoint pos);
  void onMenuClick(tipsMenu index);
  void onRealDealRowClicked(const QModelIndex& index);
  void onRealDealRowDblClicked(const QModelIndex& index);

 private:
  bool isBrokerCheckEnable() const;

 private:
  SVirtualTable* m_dealTable = nullptr;
  DefaultTableModel* m_model = nullptr;
  STableColumnSet* m_tableSet = nullptr;
  RealTimeDealModel* m_dealModel = nullptr;  // 新版数据模型
  std::vector<ETknPriceColType> m_cols;

  CEnviFilter* m_pEnviFilter = nullptr;          //
  BLHCONDITION* m_pBlh = nullptr;                //
  FilterCondition* m_pFilterCondtion = nullptr;  // 过滤条件
  FilterCondition m_stuFilterCondition;          // 过滤条件
  int m_nCorpID = 0;
  bool m_bUseTempCondition = false;
  QMenu* m_dealMenu = nullptr;
  CBondInfo* m_dealIndex = nullptr;
  MarketStreamInfo* m_dealRecord = nullptr;
  QString m_dealCopyData;
  QString m_selRowKey;
};